function InnerTable(ops) {
    var options = ops;
    var self = {
        init: function () {
            this.containerId = "div_" + options.id;
            this.id = options.id;

            var scope = $("body").scope();

            var html = options.templete;
            var el = scope.compile(html)(scope);
            $(el).prop("id", this.id);

            $(".tables").append("<div id='" + this.containerId + "'></div>");
            $("#" + this.containerId).append(el);

                this.hide();

            this._initTable(this.id);
        },

        show: function () {
            $("#" + this.containerId).removeClass("hide");
        },

        hide: function () {
            $("#" + this.containerId).addClass("hide");
        },

        /**
         * 初始化Table
         */
        _initTable: function (id) {
            var id = "#" + id;
            $(id).bootstrapTable({
                method: "get",  //使用get请求到服务器获取数据
                url: createUrl(options.dataUrl),
                locale: "zh-CN",
                striped: true,  //表格显示条纹
                pagination: options.bPaginate ? true : false, //启动分页
                pageSize: options.bPaginate ? options.pageSize : "All",  //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [10, 25, 50],  //记录数可选列表
                search: false,  //是否启用查询
                showColumns: false,  //显示下拉框勾选要显示的列
                columns: options.columns,
                sortable: false,
                showRefresh: false,  //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        pageNumber: params.pageNumber,
                        pageSize: params.pageSize
                    };

                    var pTmp = $.extend({}, options.params);
                    for (var p in pTmp) {
                        if ($.isArray(pTmp[p])) {
                            pTmp[p] = pTmp[p].join(",");
                        }
                    }
                    param = $.extend({}, pTmp || {}, param);
                    return param;
                }.bind(this),
                onLoadSuccess: function (data) {  //加载成功时执行
                    options.callback(data);
                }.bind(this),
                onLoadError: function () {  //加载失败时执行
                    alert("加载数据失败");
                },
                onPostBody: function () {
                    var scope = $("body").scope();
                    var t = $(id);
                    scope.compile(t)(scope);
                }
            });
        },

        refresh: function (param) {
            options.params = $.extend({}, options.params, param);
            var id = "#" + this.id;
            $(id).bootstrapTable("refresh");
        },

        updateRow: function (index, data) {
            var id = "#" + this.id;
            $(id).bootstrapTable("updateRow", {index: index, row: data});
        },

        updateCell: function (index, field, value) {
            var id = "#" + this.id;
            $(id).bootstrapTable("updateCell", {index: index, field: field, value: value});
        }
    };

    self.init();
    return self;
};

var tableMgr = {
    tables: [],
    create: function (options) {
        var id = this.createId(options.key, options.value);
        options.id = id;
        var table = this.findTable(id);
        if (!table) {
            table = InnerTable(options);
            this.tables.push(table);
        } else {
            table.refresh(options.params);
        }
    },

    createId: function (key, value) {
        var id = "table_" + key.split(".").join("_") + (value + "").split(".").join("_");
        return id;
    },

    findTable: function (id) {
        var table = null;
        $(this.tables).each(function (i, v) {
            if (v.id == id) {
                table = v;
                return false;
            }
        });
        return table;
    },

    refresh: function (param) {
        $(this.tables).each(function (i, v) {
            v.refresh(param);
        });
    },

    show: function (key, value) {
        var id = this.createId(key, value);
        var table = null;
        $(this.tables).each(function (i, v) {
            if (v.id == id) {
                table = v;
            } else {
                v.hide();
            }
        });
        if (table) {
            table.show();
        }
    },

    updateRow: function (key, value, index, data) {
        var id = this.createId(key, value);
        var table = this.findTable(id);
        if (table) {
            table.updateRow(index, data);
        }
    },

    updateCell: function (key, value, index, field, data) {
        var id = this.createId(key, value);
        var table = this.findTable(id);
        if (table) {
            table.updateCell(index, field, data);
        }
    }
}